﻿
<div class="col-lg-12">
    <div class="space-20 hidden-md hidden-lg"></div>
    <div class="space-4 hidden-sm hidden-xs"></div>
    <select id="state" name="">
        <option selected="" value="-1">全部</option>
        <option value="0">正常</option>
        <option value="1">已停用</option>
    </select>
    <a href="javascript:void(0)" class="easyui-linkbutton" title="筛选" data-options="iconCls:'icon-search',plain:true,iconAlign:'right'" onclick="searchbtn(this,event)"><input class="input-small" type="text" name="" id="selecttext" value="" placeholder="请输入查询条件" style="vertical-align:middle;line-height:normal;" onclick="searchinput(this)" /></a>
    <div class="space-2"></div>
</div>

<div class="page-content">
    <table id="dg" class="easyui-datagrid" title="用户管理" style="width:100%;height:auto" data-options="
							rownumbers:true,
							checkOnSelect:false,
                            url:'/Customer/All',
							pagination:true,
							pageSize:10,
							method:'get',
							toolbar:'#tb',
							selectOnCheck:false,
							fitColumns:true,
							singleSelect:true,
							">
        <thead>
            <tr>
                <th data-options="field:'ck',checkbox:true"></th>
                <th data-options="field:'act',formatter:editbtn">操作</th>
                <th data-options="field:'State',width:80,formatter:state,align:'center'">状态</th>
                <th data-options="field:'Name',width:80">用户名</th>
                <th data-options="field:'Address',width:100">送货地址</th>
                <th data-options="field:'Phone',width:80,align:'right'">联系电话</th>
            </tr>

        </thead>
    </table>
    <div id="tb" style="height:auto;vertical-align: middle;">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" onclick="unfreeze()">批量恢复</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-no',plain:true" onclick="freeze()">批量停用</a>
    </div>
    <script type="text/javascript">
        $(function () {
            $(".nav-list li").eq(2).addClass("active");

        });
        function editbtn(value, row, index) {

            var _btn = '<button class="btn btn-inverse btn-xs" style="margin:3px;" onclick="detailsline(' + row.C_ID + ',event)">查看订单</button>';

            if (row.State == 0)
                _btn += '<button class="btn btn-danger btn-xs" style="margin:3px;" onclick="freezeline(' + row.C_ID + ',event)">禁用</button>';

            else
                _btn += '<button class="btn btn-success btn-xs" style="margin:3px;" onclick="unfreezeline(' + row.C_ID + ',event)">启用</button>';
            return _btn;
        }



        function searchinput(elem) {
            event.stopPropagation();
            $(elem).select();
        }
        function searchbtn(elem, event) {
            var e = event || window.event;
            e.stopPropagation();
            page(1, 10);
        }
        function freeze() {
            if (confirm("是否禁用选中用户？")) {
                var rows = $("#dg").datagrid("getChecked");
                var IDs = [];

                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].State == 0)
                        IDs.push(rows[i].C_ID);
                }
                var param = {};
                param.IDs = IDs;
                param.state = 1;
                if (IDs.length > 0)
                    $.ajax({
                        type: 'get',
                        url: '/Customer/BatChangeState',
                        data: param,
                        traditional: true,
                        success: function (data) {


                                var pager = $("#dg").datagrid("getPager").pagination("options");

                                page(pager.pageNumber, pager.pageSize);

                        }
                    });
            }
        }
        function unfreeze() {
            if (confirm("是否启用选中用户？")) {

                var rows = $("#dg").datagrid("getChecked");
                var IDs = [];

                for (var i = 0; i < rows.length; i++) {
                    if (rows[i].State == 1)
                        IDs.push(rows[i].C_ID);
                }

                var param = {};
                param.IDs = IDs;
                param.state = 0;
                if (IDs.length > 0)
                    $.ajax({
                        type: 'get',
                        url: '/Customer/BatChangeState',
                        data: param,
                        traditional: true,
                       // data: { 'IDs': IDs, 'state': 0 },
                        success: function (data) {


                                var pager = $("#dg").datagrid("getPager").pagination("options");

                                page(pager.pageNumber, pager.pageSize);


                        }
                    });
            }
        }
        function freezeline(UserID, event) {
            var e = event || window.event;
            e.stopPropagation();
            if (confirm("是否停用该用户？")) {

                $.ajax({
                    type: 'get',
                    url: '/Customer/ChangeState',
                    data: { 'ID': UserID, 'state': 1 },
                    success: function (data) {
                        if (data != 0) {

                            var pager = $("#dg").datagrid("getPager").pagination("options");

                            page(pager.pageNumber, pager.pageSize);
                        }
                    }
                })
            }

        }
        function unfreezeline(UserID, event) {
            var e = event || window.event;
            e.stopPropagation();
            if (confirm("是否启用该用户？")) {

                $.ajax({
                    type: 'get',
                    url: '/Customer/ChangeState',
                    data: { 'ID': UserID, 'state': 0 },
                    success: function (data) {
                        if (data != 0) {
                            var pager = $("#dg").datagrid("getPager").pagination("options");

                            page(pager.pageNumber, pager.pageSize);
                        }
                    }
                })
            }
        }
        function deleteline(elem) {
            event.stopPropagation();
        }
        //生成随机状态，测试用，请删除
        function state(value, row, index) {
            //var _random = Math.floor(Math.random() * 2);
            switch (row.State) {
                case 1:
                    return "<span class='red'>已禁用</span>";
                    break;
                case 0:
                    return "<span class='green'>正常</span>";
                    break;
                default:
                    break;
            }
        }

        function page(_pageNumber, _pageSize) {
            var p = {};
            p.pageNumber = _pageNumber;
            p.pageSize = _pageSize;
            p.selecttext = $("#selecttext").val();
            p.state = $("#state").val();
            $.ajax({
                type: 'get',
                url: '/Customer/Select',
                async: true,
                dataType: 'json',
                data: p,
                success: function (data) {

                    $("#dg").datagrid("loadData", data);
                    $("#dg").datagrid("getPager").pagination({
                        onSelectPage: function (pageNumber, pageSize) {
                            page(pageNumber, pageSize);

                        },
                        onRefresh: function (pageNumber, pageSize) {
                            page(pageNumber, pageSize);
                        }
                    });
                }
            });
        }

    </script>
</div>


@*用户订单*@
<div id="win_details" class="easyui-window" title="未完成订单" style="width:500px;height:250px;display:none;" data-options="iconCls:'icon-add',shadow:false,collapsible:false,minimizable:false,closed:true,modal:false">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="text-align:center;">
            @*<div class="space-20"></div>*@
            <table id="orders" class="easyui-datagrid" title="" style="width:100%;height:100%" data-options="
                        rownumbers:true,
                        checkOnSelect:false,
                        pagination:false,                     
                        selectOnCheck:false,
                        fitColumns:true,
                        singleSelect:true,
                        ">
                <thead>
                    <tr>
                        <th data-options="field:'state',width:80,formatter:state1,align:'center'">状态</th>
                        <th data-options="field:'goodsName',width:80">商品名称</th>
                        <th data-options="field:'amount',width:80">数量</th>
                        <th data-options="field:'startTime',width:150">下单时间</th>
                        @*<th data-options="field:'endTime',width:80">完成时间</th>*@
                        <th data-options="field:'postName',width:100">送货员</th>
                        <th data-options="field:'postPhone',width:120,align:'right'">联系电话</th>
                    </tr>

                </thead>
            </table>

        </div>
    </div>
</div>

<script>
    function detailsline(id, event) {
        var e = event || window.event;
        e.stopPropagation();
        $("#win_details").window("open");
        $.ajax({
            type: 'post',
            url: "/Customer/GetOrder/" + id,
            dataType: 'json',
            success: function (data) {


                $("#orders").datagrid("loadData", data);

            }
        });
    }



    function state1(value, row, index) {
        switch (row.state) {
            case 0: return '<span style="color:blueviolet">待分配</span>';
            case 1: return '<span style="color:aquamarine">待发货</span>';
            case 2: return '<span style="color:green">待签收</span>';
            default: return '<span style="color:forestgreen">已完成</span>';
        }
    }
</script>

